'''
Author:lyk
Function: remap images from extracted data
Depends: rootPath
save path: rootPath/remap_extract
'''
import os
import shutil
from cvRemap.utils import *
import argparse
import sys

if __name__ == '__main__':

    parser = argparse.ArgumentParser()
    parser.add_argument('--rootPath', type=str,
                        default='D:/00_indemind_lyk/ICE_I26R_I18R/ICEDataSets/902_20210705/record_2',
                        help='root path')
    opt = parser.parse_args()
    print(opt)

    rootpath = opt.rootPath
    yaml_name = "MoudleParam.yaml"
    yaml_path = os.path.join(rootpath, yaml_name)
    if not os.path.exists(yaml_path):
        print("modeule yaml missed")
        sys.exit(1)

    fisheye_init_x, fisheye_init_y = read_yaml(yaml_path)
    gray_path = os.path.join(rootpath, 'imsee_data.bag.imgs.L')
    images = os.listdir(gray_path)

    extract_path = os.path.join(rootpath, 'remap_extract')
    if not os.path.exists(extract_path):
        os.makedirs(extract_path)
    for image_name in images:
        remap_image_path = os.path.join(extract_path, image_name)
        image_path = os.path.join(gray_path, image_name)

        src_image = cv2.imread(image_path)
        if src_image is None:
            continue
        print(image_path)
        remap_image = remap_eye(src_image, fisheye_init_x, fisheye_init_y)
        cv2.imwrite(remap_image_path, remap_image)

